#region (c)2008 Lokad - New BSD license

// Copyright (c) Lokad 2008 
// Company: http://www.lokad.com
// This code is released under the terms of the new BSD licence

#endregion

using System;
using System.Logging;

namespace Photon.Logging
{
	/// <summary>
	/// Wrapper around <see cref="log4net.ILog"/>
	/// </summary>
	internal sealed class LogWrapper : ILog
	{
		private readonly log4net.ILog _inner;

		/// <summary>
		/// Creates lokad-compatible logger out of <see cref="log4net.ILog"/>
		/// </summary>
		/// <param name="inner"></param>
		public LogWrapper(log4net.ILog inner)
		{
			_inner = inner;
		}

		/// <summary>
		/// <see cref="ILog.Log(LogLevel,Exception,object)"/>
		/// </summary>
		public void Log(LogLevel level, Exception exception, object message)
		{
			switch (level)
			{
				case LogLevel.Debug:
					_inner.Debug(message, exception);
					break;
				case LogLevel.Info:
					_inner.Info(message, exception);
					break;
				case LogLevel.Warn:
					_inner.Warn(message, exception);
					break;
				case LogLevel.Error:
					_inner.Error(message, exception);
					break;
				case LogLevel.Fatal:
					_inner.Fatal(message, exception);
					break;
				default:
					throw new ArgumentOutOfRangeException("level");
			}
		}

		/// <summary>
		/// <see cref="ILog.Log(LogLevel,object)"/>
		/// </summary>
		public void Log(LogLevel level, object message)
		{
			switch (level)
			{
				case LogLevel.Debug:
					_inner.Debug(message);
					break;
				case LogLevel.Info:
					_inner.Info(message);
					break;
				case LogLevel.Warn:
					_inner.Warn(message);
					break;
				case LogLevel.Error:
					_inner.Error(message);
					break;
				case LogLevel.Fatal:
					_inner.Fatal(message);
					break;
				default:
					throw new ArgumentOutOfRangeException("level");
			}
		}
	}
}